//
//  PlanVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/2.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "PlanVC.h"
#import "Plan_Recommendation.h"
#import "LabCell.h"
#import "QXMaskView.h"
#import "PlanTypeView.h"
#import "PlanRankingCell.h"
#import "PlanRecommendView.h"
#import "SearchVC.h"
#import "PlanPeopleVC.h"
#import "PlanVM.h"
#import "NewPlanLotteryVC.h"
#import "MJRefresh.h"
@interface PlanVC ()
@property (nonatomic ,strong) NSArray          *typeArr;
@property (nonatomic ,strong) NSArray          *rightArr;
@property (nonatomic ,strong) PlanTypeView        *typeView;
@property (nonatomic ,strong) NSMutableArray   *dataArr;
@property (nonatomic ,strong) PlanRecommendView *recommendView;


@property (nonatomic ,assign)NSInteger pageSize;
@property (nonatomic ,assign)NSInteger page;

@end

@implementation PlanVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.pageSize=10;
//    self.title=[NSString stringWithFormat:@"%@-计划",self.lotteryModel.Name];
//    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithCustomView:[self rightItemView:@"近10期"]];
//    self.navigationItem.rightBarButtonItem=rightItem;
//
//    self.recommendView.pageSize = self.pageSize;
    
    self.view.backgroundColor=DEFAULTBGCOLOR;
}


-(void)setLotteryModel:(LotteryTypeModel *)lotteryModel{
    
    
    
    [self.recommendView cancleTimer];
    [self.recommendView removeFromSuperview];
    self.recommendView = nil;
    
    self.recommendView.lotteryModel=lotteryModel;
    self.recommendView.pageSize=self.pageSize;

    
}


-(void)cancleTimer{
    
    [self.recommendView cancleTimer];
    
}

- (void)viewWillDisappear:(BOOL)animated{
     [self.recommendView cancleTimer];
}
- (void)backClick{
    [super backClick];
    [self.recommendView cancleTimer];
}



- (void)onclickRight:(UIButton *)sender{
    WS(weakSelf);
    QXMaskView *maskView=[[QXMaskView alloc]
                           initWithRightItemTitles:self.rightArr];
    maskView.JXBMaskViewBlock=^(NSInteger tag){
        weakSelf.pageSize=[weakSelf.rightArr[tag] integerValue];
        weakSelf.recommendView.pageSize=weakSelf.pageSize;
        UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithCustomView:[weakSelf rightItemView:[NSString stringWithFormat:@"近%@",weakSelf.rightArr[tag]]]];
        weakSelf.navigationItem.rightBarButtonItem=rightItem;
    };
}

#pragma mark -- 懒加载
- (NSArray *)rightArr{
    if (!_rightArr) {
        _rightArr=[[NSArray alloc]initWithObjects:@"5期",@"7期",@"10期",@"12期",@"15期",@"20期", nil];
    }
    return _rightArr;
}

- (UIButton *)rightItemView:(NSString *)title{
    CGSize size=[TGTools boundingRectWithString:title withSize:CGSizeMake(200, 20) anfont:12];
    UIButton *rithtItem=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, size.width+20, 20)];
    rithtItem.layer.masksToBounds=YES;
    rithtItem.layer.borderColor=[UIColor whiteColor].CGColor;
    rithtItem.layer.borderWidth=.7;
    rithtItem.layer.cornerRadius=2.0;
    [rithtItem setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rithtItem.titleLabel.font=[UIFont systemFontOfSize:12];
    [rithtItem setTitle:title forState:UIControlStateNormal];
    [rithtItem setImage:[UIImage imageNamed:@"white_angle"] forState:UIControlStateNormal];
    [rithtItem verticalImageAndTitle:size.width-5 andImage:[UIImage imageNamed:@"white_angle"]];
    
    [rithtItem addTarget:self action:@selector(onclickRight:) forControlEvents:UIControlEventTouchUpInside];
    return rithtItem;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (PlanRecommendView *)recommendView{
    if (!_recommendView) {
       
        
        _recommendView=[[PlanRecommendView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        WS(weakSelf);
        _recommendView.lookeMore = ^(NSString *newNum) {
            if ([UserModel userModel].UserId.length>0) {
                NewPlanLotteryVC *vc=[[NewPlanLotteryVC alloc]init];
                vc.title=weakSelf.title;
                for (int i=0; i<weakSelf.recommendView.recommendModel.arr.count; i++) {
                    PlanRecommendModel *planModel=weakSelf.recommendView.recommendModel.arr[i];
                    if (![planModel.Issue isEqualToString:newNum]) {
                        [weakSelf.recommendView.recommendModel.arr removeObjectAtIndex:i];
                        i-=1;
                    }
                }
                vc.recommendModel=weakSelf.recommendView.recommendModel;
                vc.lotteryTypeModel=weakSelf.recommendView.lotteryModel;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }else{
                [[BaseVM manage] login];
            }
        };
        //    _recommendView.lotteryModel=self.lotteryModel;
        [self.view addSubview:_recommendView];
        [_recommendView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self.view);
            make.bottom.equalTo(weakSelf.view).with.offset(iphoneBottom);
        }];
    
    }
    return _recommendView;
}

-(void)dealloc{
    
    [self.recommendView cancleTimer];

    NSLog(@"planVC。销毁");
   
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
@end
